class Shape{
    public void draw(){
        System.out.println("画图形！");
    }
}
class Rect extends Shape{
    @Override
    public void draw() {
        System.out.println("画矩形！");
    }
}
class Cycle extends Shape{
    @Override
    public void draw() {
        System.out.println("画圆！");
    }
}
class Flower extends Shape{
    @Override
    public void draw() {
        System.out.println("❀！");
    }
}

public class Test2 {
   /* public static void drawMap(Shape shape){
        shape.draw();
    }*/
   /* public static void drawMap2() {
        Rect rect = new Rect();
        Cycle cycle = new Cycle();
        Flower flower = new Flower();
        //cycle rect cycle rect flower
        String[] shapes = {"cycle", "rect", "cycle", "rect", "flower"};
        for (String s :shapes) {
            if(s.equals("cycle")) {
                cycle.draw();
            }else if(s.equals("rect")) {
                rect.draw();
            }else {
                flower.draw();
            }
        }
    }*/
    public static void drawMap3() {
        Cycle cycle = new Cycle();
        Flower flower = new Flower();
        Rect rect = new Rect();
        //向上转型
        Shape[] shapes = {cycle, rect, cycle, rect, flower};//里边的每个类型就是Shape类型

        for (Shape shape : shapes) {
            shape.draw();
        }
    }
    public static void main(String[] args) {
            drawMap3() ;
//        drawMap2();
        /*Rect rect = new Rect();
        Cycle cycle = new Cycle();
        drawMap(rect);
        drawMap(cycle);//将引用cycle作为参数传给drawMap方法，drawMap这样就构成了多态
        drawMap(new Flower());//将new的对象作为参数，drawMap方法用形参shape接收，这就构成了多态
*/
    }
}
